package ch.thomasmueller.saltyfiles.transformer;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;

public class DES extends Transformer{

	protected int iterationCount = 1017;

	public DES(char[] aPassoword, byte[] someSalt)
	{
		super(aPassoword, someSalt);
		algorithm = "PBEWithMD5AndDES";
	}
	
	
	protected Cipher initCipher(int mode) throws Exception
	{

		PBEKeySpec keySpec = new PBEKeySpec(password);
		SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
		SecretKey key = keyFactory.generateSecret(keySpec);
		PBEParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);
		Cipher cipher = Cipher.getInstance(algorithm);
		cipher.init(mode, key, paramSpec);
		return cipher;
	}
}
